Support for promises has been made more general in ODF Release 1. It is now easier to promise multiple data types and to use promises for linking. This document outlines the basic steps you need to do to implement promises, and provides some boilerplate code you can copy and adapt to your part.
Basic Steps
1) Subclass FW_CPromise
Override FulfillPromise
2) In the Externalize method of your Content class:
Instantiate a promise
Call promise->Promise(ev, …) for every data type you support
For an example of promises in the sample parts, see the CDrawSelectionPromise class and the method CDrawSelectionContent::Externalize in ODFDraw.
The example code in the next section assumes the existence of the following Content classes:
CPromisedContent - designates promised data
CSelectedContent - designates selected data
CPublishedContent - designates published data (the source of a link)
Boilerplate Code
1) Subclass FW_CPromise
class CMyPromise : public FW_CPromise
{
public:
CMyPromise(Environment* ev,
FW_EStorageKinds storageKind,
FW_CCloneInfo* cloneInfo,
CPromisedContent* promisedContent);
virtual ~CMyPromise();
virtual void FulfillPromise(Environment* ev,
ODStorageUnitView* promiseSUView,
ODPropertyName propertyName,
ODValueType valueType,
FW_CCloneInfo* cloneInfo);
private:
CPromisedContent* fPromisedContent;
};
CMyPromise::CMyPromise(Environment* ev,
FW_EStorageKinds storageKind,
FW_CCloneInfo* cloneInfo,
CPromisedContent* promisedContent)
: FW_CPromise(ev, storageKind, cloneInfo),
fPromisedContent(promisedContent)
{
// Mark content as promised (part-specific)
}
CMyPromise::~CMyPromise()
{
// Unmark promised content (part-specific)
delete fPromisedContent;
}
void CMyPromise::FulfillPromise(Environment* ev,
ODStorageUnitView* promiseSUView,
ODPropertyName propertyName,
ODValueType valueType,
FW_CCloneInfo* cloneInfo)
{
// Check the value type and write only that type to the storage unit
if (FW_PrimitiveStringEqual(valueType, kMyPartKind))
The OpenDoc guidelines say that when a promise is fulfilled you must supply the source content that was selected at the time the promise was written. This means that your part needs to keep track of which data is promised. When promised data is about to be changed or deleted, you need to either fulfill the promise or save the unchanged data for later fulfillment. Sorry, folks! That’s the way it is.